package com.group.eams.controller;






import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.MaintenVendorQueryDto;
import com.group.eams.pojo.entity.MaintenVendor;
import com.group.eams.pojo.vo.MaintenVendorListVo;
import com.group.eams.service.MaintenVendorService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




/**
 * 维保商管理(MaintenVendor)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/maintenVendor")
public class MaintenVendorController  {
    /**
     * 服务对象
     */
    @Autowired
    private MaintenVendorService maintenVendorService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(MaintenVendorQueryDto maintenVendorQueryDto){

        Page<MaintenVendorListVo> page=maintenVendorService.findByQueryDto(maintenVendorQueryDto);
        return Result.buildSuccess(page.getTotal(), page.getRecords());

    }

    @RequestMapping(value = "/findById",method = RequestMethod.GET)
    public Result findById(@RequestParam Long id){
        MaintenVendor maintenVendor = maintenVendorService.getById(id);
        return Result.buildSuccess(maintenVendor);
    }


    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll() {
        return Result.buildSuccess(maintenVendorService.list());
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody MaintenVendor maintenVendor){
        boolean result = maintenVendorService.save(maintenVendor);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody MaintenVendor maintenVendor){
        LambdaUpdateWrapper<MaintenVendor> queryWrapper = new LambdaUpdateWrapper<>();
        queryWrapper.eq(MaintenVendor::getId, maintenVendor.getId());
        boolean result = maintenVendorService.update(maintenVendor, queryWrapper);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(@RequestParam Long id){
        LambdaQueryWrapper<MaintenVendor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MaintenVendor::getId, id);
        boolean result = maintenVendorService.remove(queryWrapper);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        LambdaQueryWrapper<MaintenVendor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(MaintenVendor::getId, batchDeleteDto.getIds());
        boolean result = maintenVendorService.remove(queryWrapper);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }



    }

